/**
 * This program is free software but WITHOUT ANY WARRANTY OR CONDITIONS OF ANY KIND.
 *
 * Copyright (C) 2008-2012 www.pretty-tools.com
 */

/**
 * Manages dialog and other windows of web slide show
 */
var wsshWindowManager = {
    logger: yrprxFactory.createLogger("wsshWindowManager"),
    globalDialogKeeper: null
};

wsshWindowManager.openSlideShow = function(images, title)
{
    if (!title)
        title = window.content.document.title;

    try
    {
        if (!this.globalDialogKeeper)
            this.globalDialogKeeper = yrprxFactory.getGlobalDialogKeeper();

        if (this.globalDialogKeeper.theLastSlideShowDialog)
        {
            var dialogWindow = this.globalDialogKeeper.theLastSlideShowDialog.addImages(images);
            dialogWindow.focus();
            return dialogWindow;
        }
    }
    catch(ex)
    {
        if (!this.logger)
            this.logger = yrprxFactory.createLogger("wsshWindowManager");

        if (this.logger.enabled) this.logger.error("constructor: ", ex);
    }

    return window.openDialog("chrome://webslideshow/content/ui/SlideShow.xul", "", "chrome,titlebar=no,toolbar=no,width=" + screen.width + ",height="+screen.height, images, title);
}

wsshWindowManager.openImportRules = function(rulesURL)
{
    return window.openDialog("chrome://webslideshow/content/ui/ImportRules.xul", "", "chrome,centerscreen,resizable", rulesURL);
}

wsshWindowManager.openSaveImagesProgressDialog = function(sources, destFolder)
{
    return window.openDialog("chrome://webslideshow/content/ui/SaveImagesProgressDialog.xul", "", "chrome,centerscreen", sources, destFolder);
}

wsshWindowManager.openOptions = function()
{
    return window.openDialog("chrome://webslideshow/content/ui/Options.xul", "WebSlideShowOptions", "chrome,centerscreen,modal,resizable");
}

wsshWindowManager.openRule = function(param)
{
    return window.openDialog("chrome://webslideshow/content/ui/Rule.xul", "WebSlideShowRule", "chrome,centerscreen,modal", param);
}

wsshWindowManager.newXMLHttpRequest = function()
{
    return new XMLHttpRequest();
}
